<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="120px">
      <el-form-item label="免疫流水号" prop="serialNo">
        <el-input
          v-model="queryParams.serialNo"
          placeholder="请输入免疫流水号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="免疫证号" prop="immuneNo">
        <el-input
          v-model="queryParams.immuneNo"
          placeholder="请输入免疫证号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="预约受理时间" prop="acceptTime">
        <el-date-picker clearable size="small"
          v-model="queryParams.acceptTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择预约受理时间">
        </el-date-picker>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['dogs:immune:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['dogs:immune:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['dogs:immune:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          :loading="exportLoading"
          @click="handleExport"
          v-hasPermi="['dogs:immune:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="immuneList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="ID" align="center" prop="id" />
      <el-table-column label="免疫流水号" align="center" prop="serialNo" />
      <el-table-column label="免疫证号" align="center" prop="immuneNo" />
      <el-table-column label="免疫类型" align="center" prop="immuneType" />
      <el-table-column label="犬主姓名" align="center" prop="masterName" />
      <el-table-column label="动物名称" align="center" prop="petName" />
      <el-table-column label="犬只证号" align="center" prop="petCode" />
      <el-table-column label="动物性别" align="center" prop="petSex" />
      <el-table-column label="动物种类" align="center" prop="petType" />
      <el-table-column label="月龄" align="center" prop="petAge" />
      <el-table-column label="区" align="center" prop="addressArea" />
      <el-table-column label="街道" align="center" prop="addressStreet" />
      <el-table-column label="自然村" align="center" prop="addressVillage" />
      <el-table-column label="详细地址" align="center" prop="addressDetail" />
      <el-table-column label="疫苗名称" align="center" prop="goodsName" />
      <el-table-column label="疫苗批号" align="center" prop="batchNo" />
      <el-table-column label="状态" align="center" prop="status" />
      <el-table-column label="免疫日期" align="center" prop="immuneDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.immuneDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="下次免疫日期" align="center" prop="immuneNextDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.immuneNextDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="打证发证日期" align="center" prop="printTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.printTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="创建人" align="center" prop="createdBy" />
      <el-table-column label="创建时间" align="center" prop="createdTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createdTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="修改人" align="center" prop="modifyBy" />
      <el-table-column label="修改时间" align="center" prop="modifyTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.modifyTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="兽医姓名" align="center" prop="veterinaryName" />
      <el-table-column label="兽医证号" align="center" prop="veterinaryCardNo" />
      <el-table-column label="兽医电话" align="center" prop="veterinaryPhone" />
      <el-table-column label="免疫照片" align="center" prop="photo" />
      <el-table-column label="预约受理人" align="center" prop="acceptBy" />
      <el-table-column label="预约受理时间" align="center" prop="acceptTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.acceptTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="预约受理意见" align="center" prop="acceptOpinion" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['dogs:immune:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['dogs:immune:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改城市犬只免疫登记对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="免疫流水号" prop="serialNo">
          <el-input v-model="form.serialNo" placeholder="请输入免疫流水号" />
        </el-form-item>
        <el-form-item label="免疫证号" prop="immuneNo">
          <el-input v-model="form.immuneNo" placeholder="请输入免疫证号" />
        </el-form-item>
        <el-form-item label="主人id" prop="masterId">
          <el-input v-model="form.masterId" placeholder="请输入主人id" />
        </el-form-item>
        <el-form-item label="犬只id" prop="dogId">
          <el-input v-model="form.dogId" placeholder="请输入犬只id" />
        </el-form-item>
        <el-form-item label="免疫点id" prop="immunepointId">
          <el-input v-model="form.immunepointId" placeholder="请输入免疫点id" />
        </el-form-item>
        <el-form-item label="疫苗入库详情id" prop="goodsInDetailId">
          <el-input v-model="form.goodsInDetailId" placeholder="请输入疫苗入库详情id" />
        </el-form-item>
        <el-form-item label="执业兽医id" prop="veterinaryId">
          <el-input v-model="form.veterinaryId" placeholder="请输入执业兽医id" />
        </el-form-item>
        <el-form-item label="免疫类型" prop="immuneType">
          <el-select v-model="form.immuneType" placeholder="请选择免疫类型">
            <el-option label="请选择字典生成" value="" />
          </el-select>
        </el-form-item>
        <el-form-item label="犬主姓名" prop="masterName">
          <el-input v-model="form.masterName" placeholder="请输入犬主姓名" />
        </el-form-item>
        <el-form-item label="动物名称" prop="petName">
          <el-input v-model="form.petName" placeholder="请输入动物名称" />
        </el-form-item>
        <el-form-item label="犬只证号" prop="petCode">
          <el-input v-model="form.petCode" placeholder="请输入犬只证号" />
        </el-form-item>
        <el-form-item label="动物性别" prop="petSex">
          <el-select v-model="form.petSex" placeholder="请选择动物性别">
            <el-option label="请选择字典生成" value="" />
          </el-select>
        </el-form-item>
        <el-form-item label="动物种类" prop="petType">
          <el-select v-model="form.petType" placeholder="请选择动物种类">
            <el-option label="请选择字典生成" value="" />
          </el-select>
        </el-form-item>
        <el-form-item label="区" prop="addressArea">
          <el-input v-model="form.addressArea" placeholder="请输入区" />
        </el-form-item>
        <el-form-item label="街道" prop="addressStreet">
          <el-input v-model="form.addressStreet" placeholder="请输入街道" />
        </el-form-item>
        <el-form-item label="自然村" prop="addressVillage">
          <el-input v-model="form.addressVillage" placeholder="请输入自然村" />
        </el-form-item>
        <el-form-item label="详细地址" prop="addressDetail">
          <el-input v-model="form.addressDetail" placeholder="请输入详细地址" />
        </el-form-item>
        <el-form-item label="疫苗名称" prop="goodsName">
          <el-input v-model="form.goodsName" placeholder="请输入疫苗名称" />
        </el-form-item>
        <el-form-item label="疫苗批号" prop="batchNo">
          <el-input v-model="form.batchNo" placeholder="请输入疫苗批号" />
        </el-form-item>
        <el-form-item label="状态">
          <el-radio-group v-model="form.status">
            <el-radio label="1">请选择字典生成</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="免疫日期" prop="immuneDate">
          <el-date-picker clearable size="small"
            v-model="form.immuneDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择免疫日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="下次免疫日期" prop="immuneNextDate">
          <el-date-picker clearable size="small"
            v-model="form.immuneNextDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择下次免疫日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="打证发证日期" prop="printTime">
          <el-date-picker clearable size="small"
            v-model="form.printTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择打证发证日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="创建人" prop="createdBy">
          <el-input v-model="form.createdBy" placeholder="请输入创建人" />
        </el-form-item>
        <el-form-item label="创建时间" prop="createdTime">
          <el-date-picker clearable size="small"
            v-model="form.createdTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择创建时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="修改人" prop="modifyBy">
          <el-input v-model="form.modifyBy" placeholder="请输入修改人" />
        </el-form-item>
        <el-form-item label="修改时间" prop="modifyTime">
          <el-date-picker clearable size="small"
            v-model="form.modifyTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择修改时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="兽医姓名" prop="veterinaryName">
          <el-input v-model="form.veterinaryName" placeholder="请输入兽医姓名" />
        </el-form-item>
        <el-form-item label="兽医证号" prop="veterinaryCardNo">
          <el-input v-model="form.veterinaryCardNo" placeholder="请输入兽医证号" />
        </el-form-item>
        <el-form-item label="兽医电话" prop="veterinaryPhone">
          <el-input v-model="form.veterinaryPhone" placeholder="请输入兽医电话" />
        </el-form-item>
        <el-form-item label="免疫照片" prop="photo">
          <el-input v-model="form.photo" placeholder="请输入免疫照片" />
        </el-form-item>
        <el-form-item label="预约受理人" prop="acceptBy">
          <el-input v-model="form.acceptBy" placeholder="请输入预约受理人" />
        </el-form-item>
        <el-form-item label="预约受理时间" prop="acceptTime">
          <el-date-picker clearable size="small"
            v-model="form.acceptTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择预约受理时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="预约受理意见" prop="acceptOpinion">
          <el-input v-model="form.acceptOpinion" placeholder="请输入预约受理意见" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listImmune, getImmune, delImmune, addImmune, updateImmune, exportImmune } from "@/api/dogs/immune";

export default {
  name: "Immune",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 城市犬只免疫登记表格数据
      immuneList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        serialNo: null,
        immuneNo: null,
        immuneType: null,
        masterName: null,
        petName: null,
        petCode: null,
        petSex: null,
        petType: null,
        petAge: null,
        addressArea: null,
        addressStreet: null,
        addressVillage: null,
        addressDetail: null,
        goodsName: null,
        batchNo: null,
        status: null,
        immuneDate: null,
        immuneNextDate: null,
        printTime: null,
        createdBy: null,
        createdTime: null,
        modifyBy: null,
        modifyTime: null,
        veterinaryName: null,
        veterinaryCardNo: null,
        veterinaryPhone: null,
        photo: null,
        acceptBy: null,
        acceptTime: null,
        acceptOpinion: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询城市犬只免疫登记列表 */
    getList() {
      this.loading = true;
      listImmune(this.queryParams).then(response => {
        this.immuneList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        serialNo: null,
        immuneNo: null,
        masterId: null,
        dogId: null,
        immunepointId: null,
        goodsInDetailId: null,
        veterinaryId: null,
        immuneType: null,
        masterName: null,
        petName: null,
        petCode: null,
        petSex: null,
        petType: null,
        petAge: null,
        addressArea: null,
        addressStreet: null,
        addressVillage: null,
        addressDetail: null,
        goodsName: null,
        batchNo: null,
        status: 0,
        immuneDate: null,
        immuneNextDate: null,
        printTime: null,
        createdBy: null,
        createdTime: null,
        modifyBy: null,
        modifyTime: null,
        veterinaryName: null,
        veterinaryCardNo: null,
        veterinaryPhone: null,
        photo: null,
        acceptBy: null,
        acceptTime: null,
        acceptOpinion: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加城市犬只免疫登记";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getImmune(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改城市犬只免疫登记";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateImmune(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addImmune(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除城市犬只免疫登记编号为"' + ids + '"的数据项？').then(function() {
        return delImmune(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$modal.confirm('是否确认导出所有城市犬只免疫登记数据项？').then(() => {
        this.exportLoading = true;
        return exportImmune(queryParams);
      }).then(response => {
        this.$download.name(response.msg);
        this.exportLoading = false;
      }).catch(() => {});
    }
  }
};
</script>
